document.getElementById('loginForm').addEventListener('submit', function(e) {
    e.preventDefault();
    
    const formData = new FormData(this);
    
    fetch('/api/login', {
        method: 'POST',
        body: formData
    })
    .then(response => response.json())
    .then(data => {
        if (data.success) {
            window.location.href = '/';
        } else {
            alert(data.message);
            // 刷新验证码
            document.querySelector('.captcha-group img').click();
        }
    })
    .catch(error => {
        console.error('Error:', error);
        alert('登录失败，请重试');
    });
}); 